package com.lgj.web.sys.controller;

import com.lgj.result.ResultBody;
import com.lgj.web.sys.model.SysResourceCategory;
import com.lgj.web.sys.service.SysResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("/resourceCategory")
public class SysResourceCategoryController {
    @Autowired
    private SysResourceCategoryService resourceCategoryService;

    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public ResultBody<List<SysResourceCategory>> listAll() {
        List<SysResourceCategory> resourceList = resourceCategoryService.listAll();
        return ResultBody.success(resourceList);
    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public ResultBody create(@RequestBody SysResourceCategory SysResourceCategory) {
        int count = resourceCategoryService.create(SysResourceCategory);
        if (count > 0) {
            return ResultBody.success(count);
        } else {
            return ResultBody.fail();
        }
    }

    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public ResultBody update(@PathVariable Long id,
                               @RequestBody SysResourceCategory SysResourceCategory) {
        int count = resourceCategoryService.update(id, SysResourceCategory);
        if (count > 0) {
            return ResultBody.success(count);
        } else {
            return ResultBody.fail();
        }
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public ResultBody delete(@PathVariable Long id) {
        int count = resourceCategoryService.delete(id);
        if (count > 0) {
            return ResultBody.success(count);
        } else {
            return ResultBody.fail();
        }
    }
}
